package com.face.server.controller;

import com.face.RespMsg;
import com.face.server.repository.DormitoryRepository;
import com.face.server.service.DormitoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

/**
 * Created by ryan on 2018/3/15.
 */
@RestController
@RequestMapping("/dormitory")
public class DormitoryController {

    @Autowired
    private DormitoryRepository dormitoryRepository;

    @Autowired
    private DormitoryService dormitoryService;

    @GetMapping("/listDorimtories")
    public RespMsg listDormitories(@PageableDefault(sort = "dormitoryBuildNum",size = 10000)Pageable pageable, @RequestParam(required = false) String key1, @RequestParam(required = false) String key2){
        return RespMsg.build(dormitoryService.listDormitories(pageable,key1,key2));
    }

    @GetMapping("/listStuInDorm/{id}")
    public RespMsg listStuInDorm(@PathVariable String id){
        return RespMsg.build(dormitoryService.listStuInDorm(id));
    }

    @GetMapping("/listMyDormitories")
    public RespMsg listMyDormitories(@PageableDefault(sort = "dormitoryBuildNum",size = 10000)Pageable pageable, @RequestParam(required = false) String key1, @RequestParam(required = false) String key2, Principal principal){
        return RespMsg.build(dormitoryService.listDormitories(pageable,key1,key2,principal));
    }
}
